<%@ include file="/WEB-INF/views/commonJSTL.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>${s_UserPharmacy.pharmacy.name}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%@ include file="/WEB-INF/views/commonResources.jsp" %>
<script src="<c:url value="/resources/js/jquery.jstree.js" />"></script>

<script type="text/javascript">
	$(document).ready(function(){	
		$("#formGrupo").validate({
			/* rules: {
	             'userpharmacy.userId.login': {
	            	 remote: "validateUsernameUnique"
	             }      
	         },	         
	         messages:{
	             'userpharmacy.userId.login':{
	                 remote: jQuery.format("User {0} already exists")
	             }
	         },  */
	        submitHandler: function(form) {
	       		form.submit();
	        }
	    });
		//permit only numbers
		$('.numberOnlyNumber').keyup(function () {
	         if (this.value != this.value.replace(/[^0-9]/g,'')) {
	            this.value = this.value.replace(/[^0-9]/g, '');
	         }
	     });
		
		//permit only text
		$('.lettersOnly').keyup(function () {
	         if (this.value != this.value.replace(/[^A-Za-z\s]/g, '')) {
	            this.value = this.value.replace(/[^A-Za-z\s]/g, '');
	         }
	     });
		
	});

	function mainHumanResource(){
		location.href = "adminHumanResources?_menuId=2&_subMenuId=3";	
	}

</script>
</head>

<body>
<div id="top-wrap">
	<%@include file="../../head.jsp"  %>
	<div id="bodySpace">
		
	    <div class="clearfix" id="middle" style="position: absolute">  <!-- aqui va la ruta -->
	        <!-- aqui va el arbol de entrada -->
	        <div id="breadcrumb">
	            <ul>
                	<li><a href="<spring:url value="/mainFront?" htmlEscape="true" />">Home</a></li>	
                    <li><span style="color:#666"><fmt:message key="title.admin"/></span></li>
                    <li><span style="color:#666"><fmt:message key="title.resourceHuman"/></span></li>
                    <li class="current-page"><span class="end"><span class="middle"><fmt:message key="title.users"/></span></span></li>
                </ul>
	        </div>
	    </div>
	    
	    <div id="principal">
            <!-- izquierda -->
            <div class="cuerpo2y" style="border: 0px solid"><br/><br/><!-- estos break son necesarios ya q uso absolute en css  cuerpo izquierdo-->
                <div class="izq">
					<%@include file="../../bodyIzq.jsp" %>	
                </div>
                
                <div class="medio" style="border: 0px solid">
					
					<h2 class="decorado">
					<c:choose>		
						<c:when test="${param._pharmacyId == null}">
							<fmt:message key="show.register"/> <fmt:message key="title.user"/>
						</c:when>
						<c:otherwise>
							<fmt:message key="show.modify"/> <fmt:message key="title.user"/>
						</c:otherwise>
					</c:choose>					
					</h2></br></br> 
					
					<form:form method="post" id="formGrupo" commandName="access">   
						<form:hidden path="userpharmacy.user.userId"/>                        

						<c:set var="pharmacy" scope="page"><fmt:message key="form.selected"/> <fmt:message key="form.pharmacy"/>.</c:set>	
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.pharmacy"/>:</label>
							<div style="float: left">
							<c:forEach var="item" items="${pharmacyList}">
								<c:choose>		
									<c:when test="${param._pharmacyId != null}">
										<c:if test="${item.pharmacyId == param._pharmacyId}">
											<form:checkbox path="userpharmacy.pharmacy.pharmacyId" id="namePharmacy_${item.pharmacyId}" value="${item.pharmacyId}" class="required" title="${pharmacy}"/>
											<label for="namePharmacy_${item.pharmacyId}">${item.name}</label>										
										</c:if>
									</c:when>
									<c:otherwise>
										<div>&nbsp;&nbsp;
										<form:checkbox path="userpharmacy.pharmacy.pharmacyId" id="namePharmacy_${item.pharmacyId}" value="${item.pharmacyId}" class="required" title="${pharmacy}"/>
										<label for="namePharmacy_${item.pharmacyId}">${item.name}</label>
									</div>
									</c:otherwise>
								</c:choose>
							</c:forEach>
							</div>							
						</div>                        
						
						<br/><br/><br/><br/>
						
						<c:set var="name" scope="page"><fmt:message key="show.form.name"/>.</c:set>																																				                             												
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.name"/>:</label>
							<form:input path="userpharmacy.user.name" id="name" class="required form_input_align letterSpace lettersOnly" maxlength="25" title="${name}" autofocus="autofocus" placeholder="letras"/>
							<label class="error"><form:errors path="userpharmacy.user.name" cssClass="error"></form:errors>*</label>
						</div>
						
						<c:set var="lastNames" scope="page"><fmt:message key="show.form.lastNames"/>.</c:set>																																				                             						
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.lastNames"/>:</label>
							<form:input path="userpharmacy.user.lastName" id="lastName" class="required form_input_align letterSpace lettersOnly" maxlength="25" title="${lastNames}" placeholder="letras"/>
							<form:input path="userpharmacy.user.lastName2" id="lastName2" class="form_input_align letterSpace lettersOnly" maxlength="25" placeholder="letras"/>
							<label class="error"><form:errors path="userpharmacy.user.lastName" cssClass="error"></form:errors>*</label>
						</div>       
						
						<c:set var="ci" scope="page"><fmt:message key="show.form.ci"/>.</c:set>																																				                             
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.ci"/> :</label>
							<form:input path="userpharmacy.user.ci" id="ci" class="form_input_align required numberOnlyNumber" minlength='1' maxlength="15" title="${ci}" placeholder="números"/>
							<label class="error"><form:errors path="userpharmacy.user.ci" cssClass="error"></form:errors>*</label>
						</div> 
						                          																													
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.selected.gender"/> :</label>
							<c:choose>		
								<c:when test="${userpharmacy.userId.userId != null}">
									<c:if test="${userpharmacy.userId.genero.toString() == 'M'}">
										<form:radiobutton path="userpharmacy.user.genero" value="M" checked="checked" id="genero_M" class="required" /><label for="genero_M">&nbsp;<fmt:message key="form.male"/>&nbsp;&nbsp;</label>
										<form:radiobutton path="userpharmacy.user.genero" value="F" id="genero_F" class="required" /><label for="genero_F">&nbsp;<fmt:message key="form.female"/>&nbsp;&nbsp;</label>
									</c:if>
									<c:if test="${userpharmacy.userId.genero.toString() == 'F'}">
										<form:radiobutton path="userpharmacy.user.genero" value="M" id="genero_M" class="required" /><label for="genero_M">&nbsp;<fmt:message key="form.male"/>&nbsp;&nbsp;</label>
										<form:radiobutton path="userpharmacy.user.genero" value="F" checked="checked" id="genero_F" class="required" /><label for="genero_F">&nbsp;<fmt:message key="form.female"/>&nbsp;&nbsp;</label>
									</c:if>	
								</c:when>
								<c:otherwise>
									<form:radiobutton path="userpharmacy.user.genero" value="M" checked="checked" id="genero_M" class="required" /><label for="genero_M">&nbsp;<fmt:message key="form.male"/>&nbsp;&nbsp;</label>
									<form:radiobutton path="userpharmacy.user.genero" value="F" id="genero_F" class="required" /><label for="genero_F">&nbsp;<fmt:message key="form.female"/>&nbsp;&nbsp;</label>
								</c:otherwise>
							</c:choose>
						</div> 
						
						<c:set var="phone" scope="page"><fmt:message key="show.form.phone"/>.</c:set>																														
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.phone"/> :</label>
							<form:input path="userpharmacy.user.phone" id="phone" class="form_input_align required numberOnlyNumber" minlength='1' maxlength="15" title="${phone}" placeholder="números"/>
							<label class="error"><form:errors path="userpharmacy.user.phone" cssClass="error"></form:errors>*</label>
						</div>
						
						<c:set var="email" scope="page"><fmt:message key="show.form.email"/>.</c:set>																														
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.email"/> :</label>
							<form:input path="userpharmacy.user.email" id="email" class="form_input_align required" minlength='1' maxlength="40" title="${email}" placeholder="name@example.com"/>
							<label class="error"><form:errors path="userpharmacy.user.email" cssClass="error"></form:errors>*</label>
						</div>
						
						<c:set var="rol" scope="page"><fmt:message key="show.form.selected.rol"/>.</c:set>																								
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.selected.rol"/> :</label>
							<form:select path="userpharmacy.user.rolId.rolId" id="rol" class="form_input_align required" title="${rol}" >								   			
								<option value=""><fmt:message key="show.form.selected"/></option>
								<c:if test="${userpharmacy.user.userId == null}">
									<c:forEach var="item" items="${rolList}">
										<form:option value="${item.rolId}"><c:out value="${item.name}"/></form:option>
									</c:forEach>
								</c:if>
								<c:if test="${userpharmacy.user.userId != null}">
									<c:forEach var="item" items="${rolList}">
										<c:set var="selec" value="" />
										<c:if test="${userpharmacy.user.rolId.rolId == item.rolId}">
											<c:set var="selec" value="selected='selected'" />
										</c:if>
										<option value="${item.rolId}" ${selec}>${item.name}</option>
									</c:forEach>
								</c:if>            	
							</form:select>
							<label class="error"><form:errors path="userpharmacy.user.rolId.rolId" cssClass="error"></form:errors>*</label>
						</div>
						
						<c:set var="account" scope="page"><fmt:message key="show.form.account"/>.</c:set>																		
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.account"/> :</label>
							<form:input path="userpharmacy.user.login" id="login" class="form_input_align required" minlength='1' maxlength="15" title="${account}" placeholder="texto"/>
							<label class="error"><form:errors path="userpharmacy.user.login" cssClass="error"></form:errors>*</label>
						</div>
						
						<c:set var="password" scope="page"><fmt:message key="show.form.password"/>.</c:set>												
						<div style="clear:both;">
							<label class="form_align30"><fmt:message key="form.password"/> :</label>
							<form:input path="userpharmacy.user.password" id="password" class="required form_input_align alphanumeric" maxlength="25" title="${password}" placeholder="texto"/>
							<label class="error"><form:errors path="userpharmacy.user.password" cssClass="error"></form:errors>*</label>
						</div>
						
						<c:set var="replay" scope="page"><fmt:message key="show.form.password.replay"/>.</c:set>						
						<div style="clear:both;">
							<label class="form_align30"> <fmt:message key="form.password.replay"/> :</label>
							<form:input path="userpharmacy.user.password2" id="password2" class="required form_input_align alphanumeric" maxlength="25" title="${replay}" placeholder="texto"/>
							<label class="error"><form:errors path="userpharmacy.user.password2" cssClass="error"></form:errors>*</label>
						</div>       
												  
						<div style="clear: both">
							<label class="form_align30"><fmt:message key="form.selected.access"/> :</label>
							<label style="float:left; margin-left:0.2em;border:1px solid #959595;width: 26%;border-radius: 8px;padding: 10px 10px 10px 6px;margin-top: 1px;background-color: white;box-shadow: 0px 2px 4px #959595, 0 0 0 2px #959595 inset;position: relative">
							<div id='myTree' >
								<ul>
								<c:forEach var="menuItem" items="${menuListOptionForAccess}">
									<li id='phtml_${menuItem.menuId}' >
										<a href='#'>${menuItem.name}</a>
										<ul>
											<c:set var="cont" value="0"/>		                                             		
											<c:set var="tempDefaultOption" value="default"/>
										
											<c:forEach var="subMenuItem" items="${menuItem.submenuCollection}" >		
												<c:set var="paintSm" value=""/>		                                             		
												<c:set var="menuSubMenu" value="${subMenuItem.submenuPK.menuId}_${subMenuItem.submenuPK.submenuId}"/>
												<c:if test="${(not empty listSubmenuPainted)}" >
													<c:forEach var="sm" items="${listObjSubmenuPainted}">
														<c:set var="smString" value="${sm.submenuPK.menuId}_${sm.submenuPK.submenuId}"/>
														<c:choose>
															<c:when test="${smString == menuSubMenu}" >
																<!--<a href='#'>sm pintar ${smString}</a>	-->
																<c:choose>
																	<c:when test="${(empty sm.optionCollection)}" >
																		<c:set var="paintSm" value="jstree-checked"/>		                                             		
																	</c:when>
																	<c:when test="${(not empty subMenuItem.optionCollection[0])}">
																		<c:set var="tempOption" value="${subMenuItem.optionCollection[0]}"/>
																		<c:if test="${tempOption.name == tempDefaultOption}">
																			<c:set var="paintSm" value="jstree-checked"/>		                                             		
																		</c:if>
																	</c:when>
																</c:choose>
															</c:when>
														</c:choose>																
													</c:forEach>
												</c:if>
											<c:if test="${cont == 0}">
												<li id='100_2' title='submenu' class="jstree-checked" rel='disabled' ><a href='#'>:)</a></li>
												<c:set var="cont" value="1"/>
											</c:if>
											<li id='${subMenuItem.submenuPK.menuId}_${subMenuItem.submenuPK.submenuId}' title='submenu' class="${paintSm}">
												<a href='#'>${subMenuItem.name}</a>
												<ul>
													<c:forEach var="optionItem" items="${subMenuItem.optionCollection}">	
														<c:if test="${optionItem.name != tempDefaultOption}">
															<c:set var="paintOption" value=""/>		                                             		
															<c:set var="option" value="${optionItem.optionPK.menuId}_${optionItem.optionPK.submenuId}_${optionItem.optionPK.optionId}"/>
															<c:if test="${(not empty listOptionPainted)}" >
																<c:forEach var="op" items="${listOptionPainted}">
																	<c:choose>
																		<c:when test="${op == option}" >
																			<c:set var="paintOption" value="jstree-checked"/>
																			<!--<a href='#'>op pintar ${op}</a>-->	
																		</c:when>
																	</c:choose>																
																</c:forEach>																	
															</c:if>
															<!--<a href='#'>op: ${option} class=${paintOption}</a>-->	
															<li id='${optionItem.optionPK.menuId}_${optionItem.optionPK.submenuId}_${optionItem.optionPK.optionId}' title='option' class="${paintOption}">
																<a href='#'>${optionItem.name}</a>
															</li>
														</c:if>
													</c:forEach>
												</ul>
											</li>
											</c:forEach>
										</ul>
									</li>
								</c:forEach>                               
								</ul>
							</div>
							</label>
							<label class="error"><form:errors path="option" cssClass="error"></form:errors>*</label>
							
						</div>   
						
						 <script type="text/javascript">
							$(function () {
								//$.jstree.check_all;
								$("#myTree").jstree({
										"plugins" : [ "themes", "html_data", "checkbox", "sort", "ui" ]
								});
							   
								
								// $.show_checkboxes();
								// $.hide_checkboxes( );
								//$.jstree.uncheck_all;
								//$("#myTree");
								//$.jstree.uncheck_all ( );
							});
							
						 </script> 				
						
						<div style="clear: both">
							<label class="form_align30">&nbsp;</label>
							<table border="0" style="float: left">
								<fmt:message key="button.register" var="varSubmit" />
								<c:if test="${param._pharmacyId != null}">
									<fmt:message key="button.modify" var="varSubmit" />
								</c:if>								
								<tr>
									<td style="text-align:right"><br/><input type="submit" value="${varSubmit}" name="action"  class="boton" title="<fmt:message key="onclick.for"/> ${varSubmit}" />&nbsp;&nbsp;</td>
									<td><br/>&nbsp;&nbsp;<input type="button" value="<fmt:message key="button.cancel"/>" name="action" onclick="mainHumanResource()" class="boton" title="<fmt:message key="onclick.cancel"/>"/></td>
								</tr>
							</table>
						</div>
					</form:form>
                </div>
            </div><!--end of leftPan-->
            
            <div class="yDer" style="border: 1px solid #ccc;">
                  <%@include file="../../notices.jsp" %>                       
            </div><!--end of rightPan-->
        </div><!--end main content -->
	</div>
</div>
</body>
</html>
